// @ts-nocheck
import React, { useEffect, useState } from "react";
import { Avatar, Button } from "antd-mobile";
import { RightOutline } from "antd-mobile-icons";
import { useNavigate, useLocation } from "react-router-dom";
import "./index.less";
import List1 from "../../images/user/sq.png";
import List2 from "../../images/user/xq.png";
import List3 from "../../images/user/jr.png";
import { getCurrentUserInfo } from "@/utils/authority";
import { getPropertyCompany } from "./service";

const User: React.FC<any> = () => {
  const navigator = useNavigate();
  const userInfo = getCurrentUserInfo()?.data;
  const location = useLocation();
  const type = userInfo.userTypeName === "用户平台" ? '1' : '2'

  const [authentication, setAuthentication] = useState(1);
  const [corporation, setCorporation] = useState("");

  const list = [
    {
      id: 1,
      name: "我的社区",
      img: List1,
      url: "/communityServiceReport?convenienceService",
      navigator: "/authentication",
    },
    {
      id: 2,
      name: "我的小区",
      img: List2,
      url: "/communityServiceReport?propertyRepair",
      navigator: "/authentication",
    },
    // {
    // 	id: 3,
    // 	name: "我的家人",
    // 	img: List3,
    // 	url: "/communityServiceReport?communityMeal",
    // },
  ];
  const list1 = [
    {
      id: 1,
      name: "我的公司",
      img: List1,
      url: "",
    },
    {
      id: 2,
      name: "服务月报",
      img: List2,
      url: "/user/serviceMonthly",
    },
    // {
    // 	id: 3,
    // 	name: "平台反馈",
    // 	img: List3,
    // 	url: "",
    // },
  ];
  const getListData = async () => {
    const params = {
      userId: userInfo?.id,
    };
    try {
      const { data } = await getPropertyCompany(params);
      setCorporation(data || "");
    } catch {}
  };

  useEffect(() => {
    getListData();
  }, []);

  return (
    <div className="user-contarnier">
      <div className="header">
        <p>个人中心</p>
      </div>
      <div className="user-box">
        <div className="user-box-banner">
          <div className="user-box-banner-item">
            <div className="user-box-banner-item-left">
              <img src="../../images/user/tx.png" alt="" />
              <div className="item-left-info">
                <div>{userInfo?.realName}</div>
                <div className="info-authentication">
                  <img src="../../images/user/rz.png" alt="" />
                  <span>已认证</span>
                </div>
              </div>
            </div>
            {type == 1 && (
              <div className="user-box-banner-item-right">
                <img
                  src="../../images/user/wdxx.png"
                  alt=""
                  onClick={() => navigator("/messege", { state: { index: 2 } })}
                />
              </div>
            )}
          </div>
        </div>
        {type == 1 ? (
          <div className="user-box-list">
            <div
              className="user-box-list-item"
              onClick={() => navigator("/user/trends")}
            >
              <img src="../../images/user/dt.png" alt="" />
              <div>
                <div>我的动态</div>
                <div>
                  <RightOutline style={{ fontSize: 16, color: "#D0D6E8" }} />
                </div>
              </div>
            </div>
            <div className="user-box-list-card">
              {list.map((item) => (
                <div
                  className="user-box-list-card-item"
                  key={item.id}
                  onClick={() =>
                    navigator(item.navigator, {
                      state: { defaultInfo: userInfo },
                    })
                  }
                >
                  <img src={item?.img} alt="" />
                  <div>
                    <div>{item?.name}</div>
                    <div>
                      <RightOutline
                        style={{ fontSize: 16, color: "#D0D6E8" }}
                      />
                    </div>
                  </div>
                </div>
              ))}
            </div>
            {/* <div className="user-box-list-item">
							<img
								src="../../images/user/yjfk.png"
								alt=""
							/>
							<div>
								<div>平台反馈</div>
								<div>
									<RightOutline style={{ fontSize: 16, color: "#D0D6E8" }} />
								</div>
							</div>
						</div> */}
          </div>
        ) : (
          <>
            {list1.map((item) => (
              <div
                className="user-box-list"
                key={item.id}
                onClick={() => {
                  if (item?.url) navigator(item?.url);
                }}
              >
                <div className="user-box-list-item">
                  <img src={item.img} alt="" />
                  <div>
                    <div>{item.name}</div>
                    {item.id == 1 ? (
                      <div>{corporation}</div>
                    ) : (
                      <div>
                        <RightOutline
                          style={{ fontSize: 16, color: "#D0D6E8" }}
                        />
                      </div>
                    )}
                  </div>
                </div>
              </div>
            ))}
          </>
        )}
      </div>
    </div>
  );
};

export default User;
